<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/head_latest.inc"%>
<title>流程实体监控</title>
</head>
<body style="height:100%">
<!-- DEMO演示功能-分页列表 -->
	<!-- 这里定义了转发进入的TAB对应的菜单ID，也是TAB的属性ID值 -->
  <input type="hidden" name="menuId" id="menuId" value="${param.menuId}"/>
<div id="mainsearch" style=" width:98%">
	<div class="searchtitle">
		<span style="display:block;">${cusForm.title}</span>
	</div>
	<table style="margin-left:10px;">
       	<tr>
        	<td align="left" class="l-table-edit-td">状态: 
        	<font color="${cusForm.status == 0 ? 'orange' : (cusForm.status == 1 ? 'green' : (cusForm.status == 2 ? 'black' : 'red'))}">
        	${cusForm.statusDesc}</font>&nbsp;&nbsp;&nbsp;</td>
            <td align="left" class="l-table-edit-td">创建时间: ${cusForm.fmtCreateTime}&nbsp;&nbsp;&nbsp;</td>
            <td align="left" class="l-table-edit-td">归档时间: ${cusForm.fmtArchiveTime}</td>
        </tr>
    </table>
	<div class="navline" style="margin-bottom: 4px; margin-top: 4px;"></div>
</div>
<div style="margin-left:20px;">处理人颜色说明：<font color='orange'>██未处理</font>&nbsp;&nbsp;&nbsp;<font color='green'>██已处理</font>&nbsp;&nbsp;&nbsp;
<font color='blue'>██超时未处理</font>&nbsp;&nbsp;&nbsp;<font color='gray'>██超时已处理</font></div>
<div id="maingrid" style="margin-top: 10px"></div> 
  <script type="text/javascript">
      var grid;
  	  $(function(){
  		//列表结构
  	      grid = $("#maingrid").ligerGrid({ 
  	          columns: [
  	          	{display:"环节",name:"nodeName",width:300,type:"text",align:"center",isSort : false},
  	            {display:"环节处理方式",name:"handlerWay",width:150,type:"text",align:"center",isSort : false,
  	          	render : function(row){
	            		if(row.handlerWay==1){
	            			return "串行审核";
	            		}else if(row.handlerWay==2){
	            			return "并行审核";
	            		}else if(row.handlerWay==3){
	            			return "会签审核";
	            		}else{
	            			return "-";
	            		}
	          	}
  	            },
  	            {display:"环节视图名称",name:"viewName",width:250,type:"text",align:"center",isSort : false},
  	          	{display:"处理人",name:"handlers",width:300,type:"text",align:"center",isSort : false, 
  	            	render : function(item){
  	            		var ahs = item.actualHandler;
  	            		var html = "";
  	            		for(var i=0; i < ahs.length; i++){
  	            			if(html.length > 0) html += ",";
  	            			if(ahs[i].status == 1 || ahs[i].status == 3){
  	            				html += "<input type='checkbox' name='wid' style='display:none;' class='undoChecked' value='"+ahs[i].wid+"'/>";
  	            			}
  	            			var color = ahs[i].status == 1 ? 'orange' :  ahs[i].status == 2 ? "green" : 
  	            				ahs[i].status == 3 ? "blue" : "gray";
  	            			html += "<font class='whandler' data='"+ahs[i].actualHandlerId+"' color='"+color+"'>"+ahs[i].actualHandlerName+"</font>";
  	            		}
  	          			return html;
  	          	}}
  	          ],
  	          dataAction: 'server',toolbar: {}, 
  	          url: '${baseURL}/instance/node/nodeinstancelist/listJSON.do?fiId=${param.fiId}', sortName: 'code',
  	          width: '98%', height: '100%',heightDiff:-10, checkbox: false,usePager : false,
  	          rowHeight:23,rownumbers:true,isScroll:true,sortnameParmName:"sortName",
  	          sortorderParmName:"sortOrder",
  	      });
  		  var hasArchive = ${cusForm.status==2};
  		  var buttons = [];
	  	    if(!hasArchive){//非归档的才可以转办等
	      	  buttons.push({id : "transferShowCheck", name : "转办(显示复选框)", clickEvent : FF_TransferSClickEvent, icon : "/silkicons/control_stop_blue.png"});
	      	  buttons.push({id : "transfer", name : "转办", clickEvent : FF_TransferClickEvent, icon : "/silkicons/group_go.png"});
	      	  buttons.push({id : "transferHideCheck", name : "转办(隐藏复选框)", clickEvent : FF_TransferHClickEvent, icon : "/silkicons/control_stop.png"});
	      	  buttons.push({id : "jump", name : "跳转", clickEvent : FF_JumpClickEvent, icon : "/silkicons/link_go.png"});
	      	  buttons.push({id : "rehandle", name : "重处理", clickEvent : FF_RehandleClickEvent, icon : "/silkicons/arrow_undo.png"});
	        }
	  	  buttons.push({id : "traceOpinion", name : "流程跟踪", clickEvent : FF_TraceClickEvent, icon : "/silkicons/date_link.png"});
  	      //加载toolbar
  	      LG.createToolbarButton(grid, buttons);
  	      
  	    $(".l-toolbar-item").each(function(){
  	    	var id = $(this).attr("toolbarid");
	  	  	if(id=="transfer"||id=="transferHideCheck"){
	  	  		$(this).hide();
	  	  	}
  	  	});
  	      //加一个双击复制的扩展，以方便登陆
  	      $(".whandler").dblclick(function(){
  	    	 window.clipboardData.setData("Text",$(this).attr("data"));
  	      });
  	  });
  	  
  	      //查看流程跟踪
  	      function FF_TraceClickEvent(){
	  	    	$.ligerDialog.open({
	  				url: '${baseURL}/trace/proccesstracelist/listAll.do?id=${cusForm.boId}',
	  				height: 430,
	  				width: 800,
	  				title : "流程跟踪意见",
	  				buttons: [ 
	  				    {text: '关闭', onclick: function (item, dialog) {dialog.close();}
	  				    }]
	  	    	});
  	      }
  	  	  //转办(显示复选框)
  	      function FF_TransferSClickEvent(){
  	    	  //只是显示待办人名前的复杂框，在勾选后再去进行选人
  	    	 $(".undoChecked").show();
  	    	 $(".l-toolbar-item").each(function(){
  	  	    	var id = $(this).attr("toolbarid");
	  		  	if(id=="transferShowCheck"){
	  		  		$(this).hide();
	  		  	}else{
	  		  		$(this).show();
	  		  	}
  	  	  	 });
  	      }
  	  	  //转办(隐藏复选框)
  	      function FF_TransferHClickEvent(){
	    	  //只是显示待办人名前的复杂框，在勾选后再去进行选人
  	    	$(".undoChecked").hide();
 	    	 $(".l-toolbar-item").each(function(){
 	  	    	var id = $(this).attr("toolbarid");
	  		  	if(id=="transfer"||id=="transferHideCheck"){
	  		  		$(this).hide();
	  		  	}else{
	  		  		$(this).show();
	  		  	}
 	  	  	 });
	      }
  	  	  //转办
  	     function FF_TransferClickEvent(){
	    	  var val = $(".undoChecked").val();
	    	  if (!val || val.length <= 0) { alert("请先勾选需要转办的处理人!"); return false;}
	    	  $(this).sdAddressBook({multi : 1, onReturn : function(data){
	    		  if(!data || !data.outputValue || data.outputValue.length<=0) return false;
	    		  	jQuery.ligerDialog.confirm('您确定要将选定的处理人转办至'+data.outputText+'吗?', function (confirm) {
		              if (confirm){
		            	  
		            	  $.ligerDialog.prompt('转办意见填写',true, function (yes,value) {
		                  		if(yes){
		                  			if($.trim(value)==''){
		                  				LG.showWarn("转办意见不可为空!",function(){
		                  					FF_DeletedClickEvent();
		                  				});
		                  				return false;
		                  			}
		                  			/* value = encodeURI("转办意见："+value); 
		                  			value = encodeURI(value); */
		                  			value = "转办意见："+value;
		              	  $.ajax({
		   					type: "post",
		   					url: "${baseURL}/instance/flow/flowinstancemonitor/transfer.do",
		   					dataType : "json",
		   					data: {fiId : "${param.fiId}" , wids: val, target : data.outputValue,remark:value},
		   					beforeSend: function (){
		  		                LG.loading = true;
		  		                LG.showLoading('正在处理中...请稍候');
		  		            },
		  		            complete: function (){
		  		                LG.loading = false;	  
		  		                LG.hideLoading();
		  		            },
		   				    success: function(data){
		     					if(data.hasOk){
		     						 LG.showSuccess("操作成功!", function(){
		     							FF_Reload();
		     							$(".l-toolbar-item").each(function(){
		     				  	  	    	var id = $(this).attr("toolbarid");
		     				  	  	   		if(id=="transfer"||id=="transferHideCheck"){
		     					  		  		$(this).hide();
		     					  		  	}else{
		     					  		  		$(this).show();
		     					  		  	}
		     				  	  	  	 });
		     						 });
		     					}else{
		     						LG.showError("操作失败!"+data.message);
		     					}
		   				}
		  			  }); 
		              }
			        });
		          }
		        });
	    	  }});
	      }
  	  	  //跳转
  	      function FF_JumpClickEvent(){
	    	//先弹出选环节框
  	    	$.ligerDialog.open({
  				url: '${baseURL}/instance/node/nodeinstanceselectlist/list.do?fiId=${param.fiId}',
  				height: 430,
  				width: 400,
  				title : "环节选择",
  				buttons: [ 
  				    {text: '确定', 
  						onclick: function (item, dialog) {
  							dialog.frame.FF_Select(function(data){
  							$(".l-dialog-btn").attr("style","display:none");
  								if(data.hasOk){
  								dialog.close();
  									$.ajax({
  					   					type: "post",
  					   					url: "${baseURL}/instance/flow/flowinstancemonitor/jump.do",
  					   					dataType : "json",
  					   					data: {fiId : "${param.fiId}" , targetNodeId : data.targetNodeId,remark :data.JumpRemark },
  					   					beforeSend: function (){
  					  		                LG.loading = true;
  					  		                LG.showLoading('正在处理中...请稍候');
  					  		            },
  					  		            complete: function (){
  					  		                LG.loading = false;	  
  					  		                LG.hideLoading();
  					  		            },
  					   				    success: function(data){
  					     					if(data.hasOk){
  					     						 LG.showSuccess("操作成功!", function(){
  					     							FF_Reload();
  					     						 });
  					     					}else{
  					     						LG.showError("操作失败!"+data.message);
  					     					}
  					   				    }
  					  			  });
  								}
  								$(".l-dialog-btn").attr("style","display:block");
  							});
  						} 
  				    }, 
  					{ text: '取消', 
  						onclick: function (item, dialog) { dialog.close(); } } 
  				] 
  			});
	      }
  	  	  //重处理
		  function FF_RehandleClickEvent(){
			  jQuery.ligerDialog.confirm('您确定要将当前流程文档实例重处理吗?', function (confirm) {
	              if (confirm){
	                	  $.ligerDialog.prompt('重处理意见填写',true, function (yes,value) {
	                  		if(yes){
	                  			if($.trim(value)==''){
	                  				LG.showWarn("重处理意见不可为空!",function(){
	                  					FF_DeletedClickEvent();
	                  				});
	                  				return false;
	                  			}
	                  			value = encodeURI("重处理意见："+value); 
	                  			value = encodeURI(value);
	                  			
			              	 $.ajax({
			   					type: "post",
			   					url: "${baseURL}/instance/flow/flowinstancemonitor/rehandle.do",
			   					dataType : "json",
			   					data: {fiId : "${param.fiId}",remark:value},
			   					beforeSend: function (){
			  		                LG.loading = true;
			  		                LG.showLoading('正在处理中...请稍候');
			  		            },
			  		            complete: function (){
			  		                LG.loading = false;	  
			  		                LG.hideLoading();
			  		            },
			   				    success: function(data){
			     					if(data.hasOk){
			     						 LG.showSuccess("操作成功!", function(){
			     							FF_Reload();
			     						 });
			     					}else{
			     						LG.showError("操作失败!"+data.message);
			     					}
			   				}
			  			  }); 
	                  }
	               });
	             }
	        });
	      }
	      //一个重新加载数据方法，该方法主要作为外部框架调用使用
	      function FF_Reload(){
	    	  grid.loadData();
	      }
  </script>
</body>
</html>
